Skip to content

Add FrozenMap: a read-only map in flat arrays - #13621

Draft
dougqh wants to merge 10 commits into
dougqh/toolbox-componentfrom
dougqh/toolbox-frozen-map
Draft

dougqh wants to merge 10 commits into
dougqh/toolbox-componentfrom
dougqh/toolbox-frozen-map

Conversation

@dougqh

@dougqh dougqh commented Nov 21, 2026 •

Copy link
Copy Markdown
Contributor

What Does This Do

Stacked on #13531.

Adds FrozenMap<K, V> to the toolbox: a read-only Map, built once and then only read, held in flat arrays instead of one node per entry.

  • Layout: parallel key and value arrays, in the source map's iteration order. Up to 8 entries, a lookup scans the keys with no hashing. A larger map adds an open-addressed int[] index into the arrays, at most half full.
  • Compared with a HashMap behind an unmodifiable wrapper: it drops the node per entry, the table and the wrapper. That's about 8 B per entry plus the arrays' headers, against about 40 B per entry plus some 80 B per map.
  • Compared with Map.copyOf: it keeps the source's iteration order, and get(null) misses instead of throwing.
  • Views: entrySet, keySet and values are created on each call and never cached, so a retained map holds no view objects. HashMap keeps each view it has handed out. forEach walks the arrays without allocating.
  • Nulls: null keys are rejected, null values are allowed. The map is immutable, so it's safe to share once published.

ImmutableMapBenchmark gains FrozenMap arms:

  • get at ten keys, which uses the index;
  • get at eight keys, which scans;
  • both with distinct and with identical key instances;
  • iteration through entrySet and through forEach.

Motivation

The FFE SDK keeps a read-only Value tree for each JSON flag variant (#13484). Each JSON object holds its attributes in a HashMap behind an unmodifiable wrapper. On the scale-json benchmark fixture, that's 271k HashMap$Nodes and about 106k map and wrapper objects, out of about 1.5M objects retained. A prototype on top of #13484 (dougqh/ffe-json-hash-cons) uses an FFE-local version of this map, and its retained size is being measured now. This PR adds the general-purpose version to the toolbox.

Additional Notes

  • Measurement: see below.

Measurement

ImmutableMapBenchmark, JDK 17, run by a benchmark worker on 5 CPUs with -t 4 and about 22% steal, so compare the arms with each other rather than with the M1 table in the Javadoc. Million ops/s, median of 5 forks. Every arm allocates about 0 B/op except iterate_tagMap (72 B).

structure get get, same key iterate iterate, forEach
hashMap 265.6 485.8 50.0 –
linkedHashMap 227.8 – 147.9 –
treeMap 141.5 – 74.0 –
tagMap 140.6 246.3 22.8 56.1
Map.copyOf (MapN) 142.6 196.6 69.9 –
frozenMap, 10 keys (indexed) 219.0 321.6 232.1 154.9
frozenMap, 8 keys (scanned) 137.1 181.7 – –
stringIndex 247.0 390.6 – –
stringIndex, embedded 270.9 532.0 – –
  • get: indexed, FrozenMap beats Map.copyOf by 54% (64% with the same key instance). It's below HashMap (−18%) and StringIndex (−11%). No fork ranges overlap.
  • Iteration: entrySet iteration allocates nothing, since escape analysis removes the per-element entry, and it's the fastest iteration arm, at 3.3× Map.copyOf's. forEach is 33% slower than the iterator.
  • Scan against index: the 8-key scan was 37% slower than the 10-key index (44% with the same key instance), so the threshold was too high.

JDK 21 (same host and settings), million ops/s: FrozenMap indexed get 214.5 and same-key 335.8, against Map.copyOf's 151.2 and 229.2 (+42% and +47%), HashMap's 192.5 and 595.7, and StringIndex's 244.3 and 408.9. Iteration: 246.4 (iterator) and 147.4 (forEach), against Map.copyOf's 69.6. Everything allocates about 0 B/op.

Scan threshold: FrozenMapScanBenchmark (JDK 17, about 1% steal) sweeps 1–16 entries. Scanning clearly wins up to 3 entries (+11% get, +24% same key), ties at 4, and loses from 6; at 8 it's 17–27% slower. MAX_SCANNED is now 4: at the tie, skipping the index saves its array.

🤖 Generated with Claude Code

dougqh and others added 8 commits November 19, 2026 16:10
…dule

Moves the toolbox primitives that have no dependencies outside the JDK out of internal-api, with
their tests: Hashtable, FlatHashtable, StringIndex, ChunkedBuffer, Cursor, Maybe, the hashing
utilities, BitUtils and FNV64Hash, plus the contract annotations and the Strategy, StrategyConsumer
and NoEscape markers. Package names do not change, and internal-api re-exports the module, so
callers are unchanged.

Strings.caseInsensitiveHashCode moves to HashingUtils, which FlatHashtable uses. Strings keeps the
method and delegates to it.

The agent's shared and per-product jars exclude the module, as they do the other bootstrap
components, so each class is packaged once.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The moved classes passed under internal-api's thresholds (0.7 branch, 0.8 instruction). The new
module got the 0.9 default instead, which failed coverage verification for seven of them. Using
internal-api's thresholds keeps enforcement exactly as it was before the move.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Nothing calls the Strings delegate, so drop it and move its test next to
HashingUtils.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…cies

The toolbox was extracted from internal-api, so it keeps the strict core
performance rules in AGENTS.md and the perf-review posture. Its lockfile
now covers the test configurations too.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
It only depends on toolbox classes, plus TriFunction, which moves with it
in the same package, as Strategy did. internal-api exposes the toolbox as
an api dependency, so its users compile unchanged.

The size-manager test polls the thread state itself rather than through
test-utils, so the toolbox tests keep junit as their only dependency, and
hashIterator gets a direct test.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
ConcurrentHashtable, StringIndex and FlatHashtable are on master and now
live in components/toolbox; StringCanonicalizer and LruTable are coming.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
EscapeShapeBenchmark's arms are mergeWithStatic and mergeOfTwoAllocations
now, and "merge of several allocations" replaces the compiler term "phi".

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A map built once and then only read, held in parallel key and value
arrays in the source map's iteration order: scanned up to eight
entries, indexed by an open-addressed int[] beyond that. It drops the
node per entry, the table and any unmodifiable wrapper of a HashMap,
keeps the source order (unlike Map.copyOf), lets get(null) miss, and
never caches its views. forEach walks the arrays without allocating.

ImmutableMapBenchmark gains FrozenMap arms: get at ten keys (indexed)
and at eight (scanned), with distinct and identical key instances, and
iteration through entrySet and forEach.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@dougqh dougqh added type: feature Enhancements and improvements tag: performance Performance related changes tag: ai generated Largely based on code generated by an AI or LLM labels Nov 21, 2026
@pr-commenter

pr-commenter Bot commented Nov 21, 2026 •

Copy link
Copy Markdown

LLM Validation

LLM Validation Gate — java-agent-instructions

✅ PASS

  • No blocking-case regressions; the quality change is within noise (baseline/candidate confidence intervals overlap).

6 case(s) · quality 80.8 → 81.0 (+0.1) · win-rate 49% [43%–54%]

Details — analysis and per-case results

Analysis

Changed instruction file(s): AGENTS.md.

1 case(s) dipped but stayed within the pass bar.

  • java-documentation-only-validation-001 (advisory): won 33% of blind comparisons, quality -4.2.
    • Asked: My PR fixes one spelling mistake in an explanatory sentence in an existing Markdown document. It changes no commands, code examples, links, generated content,
    • Baseline answer: For a one-word spelling fix in prose, keep validation light. You don't need a build or tests. What to do: 1. Check the diff. Make sure the only change is the corrected word. Watch for stray whitespace, reflowed lines, or a lost final newline. 2. Check the rendered page in the GitHub PR view. This catches
    • Candidate answer: For a one-word spelling fix in prose, you only need light validation: 1. Check the diff. Run git diff master...HEAD and confirm it touches only that one word in that one file. Make sure your editor didn't also change whitespace, line endings or line wrapping. 2. Check the spelling and the rendering. Confirm

Results

  • Pairwise win-rate: 49% [43%–54%] — candidate's share of blind comparisons (90% CI; spanning 50% = no clear difference)
  • Overall quality: 80.8 → 81.0 (/100, +0.1)
  • Bad signals introduced (advisory): 0
  • Candidate criteria coverage (advisory): 23/27 (85%) — expected_criteria the candidate met; does not affect the gate
  • Blocking-case regressions: 0

Cases

Case Mode Quality Δ Win-rate (90% CI) Safety
java-core-validation-001 warn +1.7 58% [33%–84%] ok
java-unit-test-conventions-001 warn -0.3 50% [50%–50%] ok
java-premain-safety-001 warn +2.2 50% [50%–50%] ok
java-ci-download-guidance-001 warn +3.1 50% [50%–50%] ok
java-documentation-only-validation-001 🟡 warn -4.2 33% [16%–51%] ok
java-existing-spock-maintenance-001 warn -1.7 50% [50%–50%] ok

Per-dimension scores, token usage, latency, and estimated cost are in the CI job logs.

@datadog-datadog-prod-us1

datadog-datadog-prod-us1 Bot commented Nov 21, 2026 •

Copy link
Copy Markdown
Contributor

🎯 Code Coverage (details)
• Patch Coverage: 100.00%
• Overall Coverage: 60.82% (+0.02%)

This comment will be updated automatically if new data arrives.
🔗 Commit SHA: 16c8a32 | Docs | Give us feedback!

@dd-octo-sts

dd-octo-sts Bot commented Nov 21, 2026 •

Copy link
Copy Markdown
Contributor

🟢 Java Benchmark SLOs — All performance SLOs passed

Suite Status
Startup 🟢 pass

SLO thresholds are defined here based on automatically generated metrics. A warning is raised when results are within 5% of the threshold.

PR vs. master results
Scenario Candidate master Δ (95% CI of mean)
startup:insecure-bank:iast:Agent 14.02 s 13.93 s [-0.0%; +1.5%] (no difference)
startup:insecure-bank:tracing:Agent 12.91 s 12.97 s [-1.1%; +0.1%] (no difference)
startup:petclinic:appsec:Agent 17.27 s 17.18 s [-0.5%; +1.5%] (no difference)
startup:petclinic:iast:Agent 17.07 s 17.18 s [-1.6%; +0.2%] (no difference)
startup:petclinic:profiling:Agent 16.76 s 17.01 s [-2.4%; -0.6%] (maybe better)
startup:petclinic:sca:Agent 17.32 s 17.11 s [+0.5%; +2.0%] (maybe worse)
startup:petclinic:tracing:Agent 16.44 s 16.21 s [+0.3%; +2.4%] (maybe worse)

Commit: 16c8a32d · CI Pipeline · Benchmarking Platform UI


Load and DaCapo benchmarks can be triggered manually in the GitLab pipeline. Results will appear in the Benchmarking Platform UI after completion.

dougqh and others added 2 commits November 21, 2026 13:01
ImmutableMapBenchmark found the 8-key scan 37% slower than the 10-key
index. FrozenMapScanBenchmark measures get at 1 to 16 entries with the
map built to scan and to index, to place the threshold.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
FrozenMapScanBenchmark found the scan clearly faster up to 3 entries,
level at 4, and slower from 6; at 8 it was 17-27% slower than the
index. Keep scanning through 4, where skipping the index saves its
array at no measurable cost.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@dougqh
dougqh force-pushed the dougqh/toolbox-component branch 2 times, most recently from 5c9275f to 0dbdb72 Compare November 24, 2026 02:03

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

tag: ai generated Largely based on code generated by an AI or LLM tag: performance Performance related changes type: feature Enhancements and improvements

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant